<template>
  <el-tabs type="border-card" v-model="activeName">
    <el-tab-pane lazy label="抓图计划" name="first">
      <timeChoose  ref="timeChoose" :initialSchedule="schedule"></timeChoose>
      <el-button class="!mt-8 block" type="primary" @click="save" style="margin-left: 0px; width: 120px">保存</el-button>

    </el-tab-pane>
    <el-tab-pane lazy label="抓图参数" name="s">
      <para></para>
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import para from "@/views/mini/storage-management/snapshot-schedule/index.vue"
import timeChoose from '@/views/components/time.vue';
import {getSnapshotSchedule, postSnapshotSchedule} from "@/api/api2";

export default {
  components: {
    para,
    timeChoose
  },
  data() {
    return {
      activeName: 'first',
      schedule: []
    };
  },
  created() {
    getSnapshotSchedule().then(res => {
      if (res.code === 0) {
        this.schedule = res.data.daySchedules;
      } else {
        this.$message({
          message: '操作失败',
          type: 'error'
        });
      }
    })
  },
  methods: {
    save(tab, event) {
      let form = this.$refs.timeChoose.form.scheduleAction;
      postSnapshotSchedule({
        type: 'snapshot',
        daySchedules: form
      }).then(res => {
        if (res.code === 0) {
          this.$message({
            message: '保存成功',
            type: 'success'
          });
        } else {
          this.$message({
            message: '保存失败',
            type: 'error'
          });
        }
      })
    }
  }
};
</script>
